package utils;

import wrapper.FileWrapper;

import java.io.File;

/**
 * Created by lincl on 2017/5/16.
 */
public class FileModification implements IFileModification {
    ConfigBean bean;
    String classPath = FileUtils.CLASS_PATH ;
    String outPath = FileUtils.OUT_PATH ;

    public FileModification() {

    }
    public FileModification(ConfigBean bean) {
        this.bean = bean;
        if(bean!=null){
            classPath = bean.getClassesPath();
            outPath = bean.getOutPath();
        }
    }

    @Override
    public void doAction(FileWrapper fileWrapper) throws Exception {
        File oldFile = fileWrapper.getOldFile();
        File newFile = fileWrapper.getNewFile();
        //如果是java文件 去取编译的class文件
        if(oldFile.getPath().lastIndexOf(".java")!=-1){
            String p = oldFile.getPath().substring(oldFile.getPath().indexOf("\\com\\")).replace(".java", ".class");
            fileWrapper.setOldFile(new File( classPath + p) );

            fileWrapper.setNewFile(new File(outPath + "\\class" + p));
//            fileWrapper.setNewFile(new File(newFile.getPath().replace(".java", ".class")));
        }
    }
}
